﻿using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using MessageBox = System.Windows.MessageBox;

namespace Ewell.BizComponent.Reg.UI.VM
{
    /// <summary>
    /// 患者建档vm
    /// </summary>
    public class PersonCreateVm: NotifyPropertyChanged
    {
        public string menuId { get; set; }
        public string bizSourceNo { get; set; }
        public Window localWindow { get; set; }
        /// <summary>
        /// 建档后患者信息
        /// </summary>
        private PatientVm _resultPatient { get; set; }
        public PatientVm resultPatient
        {
            get { return _resultPatient; }
            set
            {
                if (_resultPatient != value)
                {
                    _resultPatient = value;
                    OnPropertyChanged(nameof(resultPatient));
                }
            }
        }
        /// <summary>
        /// 填写的建档信息
        /// </summary>
        private ExPaitentVm _selectPat;
        public ExPaitentVm selectPat { get
            {
                return _selectPat;
            } set { 
                if(value != _selectPat)
                {
                    _selectPat = value;
                    OnPropertyChanged(nameof(selectPat));
                }
            }
        }
        ///// <summary>
        ///// 选择的患者医保类型
        ///// </summary>
        //private PatientTypeVm _selectedPatientType;
        //public PatientTypeVm selectedPatientType
        //{
        //    get
        //    {
        //        return _selectedPatientType;
        //    }
        //    set
        //    {
        //        if(value != _selectedPatientType)
        //        {
        //            _selectedPatientType = value;
        //            OnPropertyChanged(nameof(selectedPatientType));
        //        }
        //    }
        //}
        ///// <summary>
        ///// 医保类型选择框
        ///// </summary>
        //private List<PatientTypeVm> _patientTypeList;
        //public List<PatientTypeVm> patientTypeList
        //{
        //    get { return _patientTypeList; }
        //    set { 
        //        if(_patientTypeList != value)
        //        {
        //            _patientTypeList = value;
        //            OnPropertyChanged(nameof(patientTypeList));
        //        }
        //    }
        //}
        /// <summary>
        /// 选择的性别
        /// </summary>
        private PersonSexVm _selectedSex;
        public PersonSexVm selectedSex
        {
            get { return _selectedSex; }
            set
            {
                if( value != _selectedSex)
                {
                    _selectedSex = value;
                    OnPropertyChanged(nameof(selectedSex));
                }
            }
        }
        /// <summary>
        /// 性别选择框
        /// </summary>
        private List<PersonSexVm> _sexList;
        public List<PersonSexVm> sexList
        {
            get { return _sexList; }
            set
            {
                if (value != _sexList)
                {
                    _sexList = value;
                    OnPropertyChanged(nameof(sexList));
                }
            }
        }

        public PersonCreateVm()
        {
            this.selectPat=new ExPaitentVm();
        }

        //public ICommand createPat => new RelayCommand(param =>
        //{
        //    SaveMemberFilingRequest request = new SaveMemberFilingRequest()
        //    {
        //        type = "0",
        //        userMember = new MemberReq()
        //        {
        //            //patientId = GuidHelper.GenerateUnique19DigitId().ToString(),
        //            name = selectPat.patientName,
        //            tel = selectPat.patientPhoneNo,
        //            patientTypeNo = selectedPatientType.no,
        //            birthday = selectPat.birth.HasValue ? selectPat.birth.Value.ToString("yyyy-MM-dd HH:mm:ss") : null,
        //            accountAddress = selectPat.contactAddrDesc,
        //            bizResourceCoding = bizSourceNo,
        //            sex = selectPat.sexCode,
        //        },
                
                
        //    };
        //    if (!string.IsNullOrWhiteSpace(selectPat.idNumber))
        //    {
        //        request.memberCardInfo = new MemberCardInfoReq()
        //        {
        //            //patientId = selectPat.patientId,
        //            cardTypeCodeA = "02",
        //            cardCodeA = selectPat.idNumber,
        //            cardTypeCodeB = "02",
        //            cardCodeB = selectPat.idNumber,
        //        };
        //    }
        //    else
        //    {
        //        request.memberCardInfo = new MemberCardInfoReq()
        //        {
        //            patientId = selectPat.patientId,
        //            cardTypeCodeA = "01",
        //            cardCodeA = selectPat.patientId,
        //            cardTypeCodeB = "01",
        //            cardCodeB = selectPat.patientId,
        //        };
        //    }

        //    MemberFilingSaveDubboService memberFilingSaveDubboService = new MemberFilingSaveDubboService();
        //    var gateWayResult = memberFilingSaveDubboService.saveMemberFiling.Post<MasterMemberInfoResp>(request);
        //    if (gateWayResult.success)
        //    {
        //        LogHelper.Debug($"诊间挂号建档成功!患者id{gateWayResult.@object.patientId}");
        //        //查询患者
        //        PersonDubboService personDubboService = new PersonDubboService();
        //        PersonPatientQueryRequest patientQueryRequest = new PersonPatientQueryRequest()
        //        {
        //            patientIds = new List<string>() { gateWayResult.@object.patientId },
        //            personInfoTypes = new List<string>() { "2" },
        //        };
        //        var gateWayPatList = personDubboService.queryPersonByExample.Post<List<PersonPatientResponse>>(patientQueryRequest);
        //        if (!gateWayPatList.success) throw new SpeedException("诊间挂号", gateWayPatList.message);
        //        if (gateWayPatList.@object?.Count > 1) throw new SpeedException("诊间挂号", "查询到了多条患者记录!请检查参数!");
        //        resultPatient = gateWayPatList.@object.FirstOrDefault().CopyProperties<PatientVm>();
        //        MessageBox.Show("建档成功!");
        //        this.localWindow.DialogResult = true;
        //        this.localWindow.Close();
        //    }
        //    else
        //    {
        //        MessageBox.Show("建档失败!" + gateWayResult.message);
        //    }
        //});
        
        //public ICommand cancel => new RelayCommand(param =>
        //{
        //    this.localWindow.Close();
        //});
    }
}
